﻿XXXX.testmultifile = {

	init : function() {
		var sm = new Ext.grid.CheckboxSelectionModel( {});
		var colM = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(), sm,
				{
					header :'name',
					dataIndex :'name',
					width :150,
					sortable :true
				}, {
					header :'type',
					dataIndex :'type',
					width :80,
					sortable :true
				}, {
					header :'code',
					dataIndex :'code',
					width :80,
					sortable :true
				}, {
					header :'file',
					dataIndex :'file',
					width :240,
					sortable :true
				} ]);
		var data = [ [ '文档1', '规范', '00123', '文档1.doc' ],
				[ '文档2', '规范', '00231', '文档2.doc' ],
				[ '文档3', '过程', '00135', '文档3.doc' ],
				[ '文档4', '过程', '00554', '文档4.doc' ] ];
		var store = new Ext.data.SimpleStore( {
			data :data,
			fields : [ 'name', 'type', 'code', 'file' ]
		});
		var grid = new Ext.grid.GridPanel( {
			renderTo :'form_testmultifile',
			id :'grid_testmultifile',
			height :tab.getInnerHeight(),
			width :tab.getInnerWidth(),
			cm :colM,
			sm :sm,
			store :store,
			tbar : [ {
				id :'m',
				text :'批量上次',
				// iconCls :'add_user',
				tooltip :'一次上传多个文件',
				handler :XXXX.testmultifile.onMultiUpload
			} ],
			// 定义分页
			bbar :System.pagingBar(store)
		});
	},

	onMultiUpload : function() {
		if (!this.dialog) {
			this.dialog = new Ext.ux.UploadDialog.Dialog( {
				url :'FileUploadServlet',
				width: 540,
			    height: 400,
				reset_on_hide :false,
				allow_close_on_upload :true,
				upload_autostart :false,
				post_var_name :'upload'
			});
			this.dialog
					.on('uploadsuccess', XXXX.testmultifile.onUploadSuccess);
		}
		this.dialog.show('m');
	},

	onUploadSuccess : function(dialog, filename, data, record) {

		var store = Ext.getCmp("grid_testmultifile").getStore();
		var R = Ext.data.Record.create( [ 'name', 'type', 'code', 'file' ]);
		store.add(new R( {
			name :filename.substring(filename.lastIndexOf('\\') + 1, filename.indexOf('.')),
			type :'规范',
			code :'1001',
			file :filename.substring(filename.lastIndexOf('\\') + 1)
		}));
	}

};

//
System.register("testmultifile", XXXX.testmultifile);